{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:17:11.148005Z",
     "iopub.status.busy": "2022-07-27T02:17:11.147455Z",
     "iopub.status.idle": "2022-07-27T02:17:11.153326Z",
     "shell.execute_reply": "2022-07-27T02:17:11.152655Z",
     "shell.execute_reply.started": "2022-07-27T02:17:11.147953Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import roc_auc_score\n",
    "import numpy as np\n",
    "from scipy.stats import rankdata\n",
    "from sklearn.linear_model import LinearRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:17:11.327557Z",
     "iopub.status.busy": "2022-07-27T02:17:11.327015Z",
     "iopub.status.idle": "2022-07-27T02:17:11.335082Z",
     "shell.execute_reply": "2022-07-27T02:17:11.334607Z",
     "shell.execute_reply.started": "2022-07-27T02:17:11.327495Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "t_true = np.random.randint(0, 2, size=1000)\n",
    "\n",
    "pred1 = t_true + np.random.randn(1000)\n",
    "pred1 = np.clip(pred1, 0, 1)\n",
    "\n",
    "pred2 = t_true + np.random.randn(1000) - 0.2\n",
    "pred2 = np.clip(pred2, 0, 1)\n",
    "\n",
    "pred3 = t_true + np.random.randn(1000) - 0.1\n",
    "pred3 = np.clip(pred3, 0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:17:11.898040Z",
     "iopub.status.busy": "2022-07-27T02:17:11.897626Z",
     "iopub.status.idle": "2022-07-27T02:17:11.908813Z",
     "shell.execute_reply": "2022-07-27T02:17:11.908183Z",
     "shell.execute_reply.started": "2022-07-27T02:17:11.897992Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.7140375941955907, 0.7406884932307235, 0.7664949835720489)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "roc_auc_score(t_true, pred1), roc_auc_score(t_true, pred2), roc_auc_score(t_true, pred3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:17:11.909933Z",
     "iopub.status.busy": "2022-07-27T02:17:11.909738Z",
     "iopub.status.idle": "2022-07-27T02:17:11.972134Z",
     "shell.execute_reply": "2022-07-27T02:17:11.971206Z",
     "shell.execute_reply.started": "2022-07-27T02:17:11.909909Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8650706942160006"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "roc_auc_score(t_true, (pred1 + pred2+ pred3) / 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:17:11.977691Z",
     "iopub.status.busy": "2022-07-27T02:17:11.977440Z",
     "iopub.status.idle": "2022-07-27T02:17:12.034941Z",
     "shell.execute_reply": "2022-07-27T02:17:12.034030Z",
     "shell.execute_reply.started": "2022-07-27T02:17:11.977673Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8575510547104799"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "roc_auc_score(t_true, (pred1 + pred2**0.2+ pred3**0.1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:17:12.896308Z",
     "iopub.status.busy": "2022-07-27T02:17:12.895739Z",
     "iopub.status.idle": "2022-07-27T02:17:12.905122Z",
     "shell.execute_reply": "2022-07-27T02:17:12.904599Z",
     "shell.execute_reply.started": "2022-07-27T02:17:12.896255Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8664093421215869"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred = rankdata(pred1) + rankdata(pred2)+ rankdata(pred3)\n",
    "pred /= 1000\n",
    "pred /= 3\n",
    "roc_auc_score(t_true, pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-07-27T02:14:06.895575Z",
     "iopub.status.busy": "2022-07-27T02:14:06.895097Z",
     "iopub.status.idle": "2022-07-27T02:14:06.901843Z",
     "shell.execute_reply": "2022-07-27T02:14:06.901326Z",
     "shell.execute_reply.started": "2022-07-27T02:14:06.895537Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 3., 2.])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rankdata([1,3,2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
